package io.renren.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.entity.Result;
import io.renren.entity.ScoreEntity;
import io.renren.service.ScoreService;
import io.renren.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * describe:
 * create @ kylin  2019/03/10
 */
@RestController
@RequestMapping("/api/score")
@Api(tags = "分数相关")
public class ApiScoreController {

    @Autowired
    private ScoreService scoreService;

    @GetMapping(value = "list")
    @ApiOperation(value = "获取所有分数")
    public Result<ScoreEntity> list() throws Exception{
        return ResultUtil.success(this.scoreService.list());
    }

    @PostMapping(value = "search")
    @ApiOperation(value = "查询某一个同学的成绩")
    public Result<ScoreEntity> search(@RequestParam("stuSubject") String stuSubject,@RequestParam("stuXuehao") String stuXuehao) throws Exception{
        QueryWrapper<ScoreEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ScoreEntity::getStuSubject,stuSubject)
        .eq(ScoreEntity::getStuXuehao,stuXuehao);
        return ResultUtil.success(this.scoreService.list(queryWrapper));
    }
}
